package com.ruoyi.web.teacher;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.teacher.domain.TQuestionBank;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teacher.domain.TPaperQuestion;
import com.ruoyi.teacher.service.ITPaperQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试卷问题Controller
 * 
 * @author ruoyi
 * @date 2024-12-01
 */
@RestController
@RequestMapping("/teacher/p_question")
public class TPaperQuestionController extends BaseController
{
    @Autowired
    private ITPaperQuestionService tPaperQuestionService;

    /**
     * 查询试卷问题列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:p_question:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPaperQuestion tPaperQuestion)
    {
        startPage();
        List<TPaperQuestion> list = tPaperQuestionService.selectTPaperQuestionList(tPaperQuestion);
        return getDataTable(list);
    }

    /**
     * 导出试卷问题列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:p_question:export')")
    @Log(title = "试卷问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPaperQuestion tPaperQuestion)
    {
        List<TPaperQuestion> list = tPaperQuestionService.selectTPaperQuestionList(tPaperQuestion);
        ExcelUtil<TPaperQuestion> util = new ExcelUtil<TPaperQuestion>(TPaperQuestion.class);
        util.exportExcel(response, list, "试卷问题数据");
    }

    /**
     * 获取试卷问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:p_question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tPaperQuestionService.selectTPaperQuestionById(id));
    }

    /**
     * 新增试卷问题
     */
    @PreAuthorize("@ss.hasPermi('teacher:p_question:add')")
    @Log(title = "试卷问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPaperQuestion tPaperQuestion)
    {
        return toAjax(tPaperQuestionService.insertTPaperQuestion(tPaperQuestion));
    }

    /**
     * 修改试卷问题
     */
    @PreAuthorize("@ss.hasPermi('teacher:p_question:edit')")
    @Log(title = "试卷问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPaperQuestion tPaperQuestion)
    {
        return toAjax(tPaperQuestionService.updateTPaperQuestion(tPaperQuestion));
    }

    /**
     * 删除试卷问题
     */
    @PreAuthorize("@ss.hasPermi('teacher:p_question:remove')")
    @Log(title = "试卷问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPaperQuestionService.deleteTPaperQuestionByIds(ids));
    }


}

